#include "resource.h"

void Resource::init()
{
	f = 0;
	valid = 0;
}

Resource::Resource()
{
	init();

}

Resource::Resource(const Resource *other)
{
	init();

	if(other!=0)
	{
		if(other->f != 0)
		{
			f = other->f;
			valid = 1;
		}
	}

}

Resource::Resource(std::fstream *filestream)
{
	init();

	if(filestream != 0)
	{
		f = filestream;
		valid = 1;
	}
}

Resource::Resource(const char *filename)
{
	init();

	f = new std::fstream(filename,std::ios_base::in | std::ios_base::binary);
	
	if(f!=0)
		valid = 1;
}

Resource::Resource(const wchar_t *filename)
{
	init();

	f = new std::fstream(filename,std::ios_base::in | std::ios_base::binary);

	if(f!=0)
		valid = 1;
}

int Resource::GetStream(std::fstream **out)
{
	if(valid)
	{
		(*out) = f;
		return 1;
	}

	return 0; //failed
}

int Resource::Valid()
{
	return valid;
}
